package classes.view.component 
{
	import classes.controller.EDataObject;
	
	import com.d4p.custom.imageLoader.ImageLoader;
	import com.d4p.custom.imageLoader.ImageLoaderEvent;
	import com.d4p.util.ExternalFontLoader;
	import com.greensock.TweenMax;
	import com.greensock.easing.Cubic;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class PopupRoomListItemSelect extends Sprite
	{
		private var _more_chk:Boolean = false;
		private var _this_num:int;
		private var _this_obj:Object;
		
		private var _img_mc:MovieClip;
		private var _c1_mc:MovieClip;
		private var _c2_mc:MovieClip;
		private var _new_mc:MovieClip;
		private var _best_mc:MovieClip;
		private var _moreBtn_mc:MovieClip;
		private var _more_mc:MovieClip;
		private var _over_btn:SimpleButton;
		private var _bg_mc:MovieClip;
		private var _no_txt:TextField;
		private var _title_txt:TextField;
		private var _cateogry_txt:TextField;
		private var _maker_txt:TextField;
		private var _detail_txt:TextField;
		
		public function PopupRoomListItemSelect() 
		{
			super();
			setLayOut();
			initListener();
			defaultSetting();
		}
		
		private function setLayOut():void
		{
			this._img_mc	=	this.getChildByName('img_mc') as MovieClip;
			this._c1_mc	=	this.getChildByName('c1_mc') as MovieClip;
			this._c2_mc	=	this.getChildByName('c2_mc') as MovieClip;
			this._new_mc	=	this.getChildByName('new_mc') as MovieClip;
			this._best_mc	=	this.getChildByName('best_mc') as MovieClip;
			this._moreBtn_mc	=	this.getChildByName('moreBtn_mc') as MovieClip;
			this._more_mc	=	this.getChildByName('more_mc') as MovieClip;
			this._bg_mc	=	this.getChildByName('bg_mc') as MovieClip;
			this._over_btn	=	this.getChildByName('over_btn') as SimpleButton;
			
			this._no_txt	=	this.getChildByName('no_txt') as TextField;
			this._title_txt	=	this.getChildByName('title_txt') as TextField;
			this._cateogry_txt	=	this.getChildByName('cateogry_txt') as TextField;
			this._maker_txt	=	this.getChildByName('maker_txt') as TextField;
			this._detail_txt	=	this.getChildByName('detail_txt') as TextField;
		}
		
		private function initListener():void
		{
			//moreBtn_mc.buttonMode = true;
			//moreBtn_mc.addEventListener(MouseEvent.CLICK, moreView);
			//
			//over_btn.addEventListener(MouseEvent.CLICK, overClick);
		}
		
		private function defaultSetting():void
		{
			//_addtop_mc.visible = false;
		}
		
		public function setData($num:int, $obj:Object):void
		{
			_this_num = $num;
			_this_obj = $obj;
			
			_no_txt.text = "";
			_title_txt.text = _this_obj.name;
			_cateogry_txt.text = _this_obj.subject;
			_maker_txt.text = _this_obj.maker;
			_detail_txt.text = _this_obj.info;
			
			_title_txt.x = _no_txt.x + _no_txt.textWidth + 4;
			_c1_mc.x = _title_txt.x + _title_txt.textWidth + 6;
			_cateogry_txt.x = _c1_mc.x + 3;
			_c2_mc.x = _cateogry_txt.x + _cateogry_txt.textWidth + 6;
			_maker_txt.x = _c2_mc.x + 3;
			
			_new_mc.visible = false;
			_best_mc.visible = false;
			if (Number(_this_obj.isNew) == 1 && Number(_this_obj.isBest) == 1) {
				_new_mc.x = _maker_txt.x + _maker_txt.textWidth + 10;
				_best_mc.x = _new_mc.x + _new_mc.width + 2;
				_new_mc.visible = true;
				_best_mc.visible = true;
			}
			if (Number(_this_obj.isNew) == 1) {
				_new_mc.x = _maker_txt.x + _maker_txt.textWidth + 10;
				_new_mc.visible = true;
				
			}
			if (Number(_this_obj.isBest) == 1) {
				_best_mc.x = _maker_txt.x + _maker_txt.textWidth + 10;
				_best_mc.visible = true;
			}
			
			
			if (_this_num % 2 !== 0) {
				_bg_mc.visible = true;
			} else {
				_bg_mc.visible = false;
			}
			//_add_mc.visible = true;
			
			//this._nick_txt.text = _this_obj.nickname;
			//this._id_txt.text = _this_obj.userid;
			//this._place_txt.text = _this_obj.nowplace;
			//this._cate_txt.text = _this_obj.category;
			
			 imagesLoad = _this_obj.img_icon;
		}
		
		
		//이미지 로드
		private function set imagesLoad($url:String):void
		{
			if($url!=""){
				//imageload.
				var imgLoader:ImageLoader = new ImageLoader();
				imgLoader.addEventListener(ImageLoaderEvent.IMAGE_COMPLETE,	onCompleteImageLoad);	
				try{
					
					imgLoader.load($url, false);
				}
				catch(e:IOErrorEvent){
					
					trace("이미지가 없습니다.");
				}
			}
		}
		private function onCompleteImageLoad(e:ImageLoaderEvent):void
		{
			e.bitmap.width = this._img_mc.width; 
			e.bitmap.height = this._img_mc.height;
			this._img_mc.addChild(e.bitmap);
			trace('imageload complete');
		}
		
//"db_no":12344 //db코드
//,"img_icon":"http://www.qdangi.com/img/db/sadf1.png" //강훈련아이콘
//,"name":"합격3관왕 엄선영어 강훈련" //db이름
//,"subject":"영어" //과목명
//,"maker":"ST&BOOKS" //출처
//,"isBest":1 //베스트여부.  1:true, 0:false
//,"isNew":1 //NEW여부.  1:true, 0:false
//,"isHit":1 //HIT여부.  1:true, 0:false
//,"info":"이 강훈련에 대한 소개" //소개
	}

}